# Based on https://github.com/kubernetes-csi/external-snapshotter/blob/master/cmd/csi-snapshotter/Dockerfile
{{- range $key, $value := .CandiVersionMap.k8s }}
  {{- $version := toString $key }}
  {{- if $value.csi.snapshotter }}
---
image: {{ $.ModuleName }}/{{ $.ImageName }}-{{ $version | replace "." "-" }}
fromImage: common/distroless
import:
  - artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact-{{ $version | replace "." "-" }}
    add: /csi-snapshotter
    to: /csi-snapshotter
    before: setup
docker:
  ENTRYPOINT: ["/csi-snapshotter"]
---
artifact: {{ $.ModuleName }}/{{ $.ImageName }}-artifact-{{ $version | replace "." "-" }}
from: {{ $.Images.BASE_GOLANG_20_ALPINE_DEV }}
shell:
  beforeInstall:
    - git clone --depth 1 --branch {{ $value.csi.snapshotter }} {{ $.SOURCE_REPO }}/kubernetes-csi/external-snapshotter.git /src
  install:
    - export GO_VERSION=${GOLANG_VERSION} GOPROXY={{ $.GOPROXY }} CGO_ENABLED=0 GOOS=linux GOARCH=amd64
    - cd /src
    {{- if semverCompare "<1.29" $version }}
    - go get google.golang.org/grpc@v1.56.3 && \
    - go mod tidy && \
    - go mod vendor && \
    {{- end }}
    - make build
    - cp bin/csi-snapshotter /csi-snapshotter
    - chown 64535:64535 /csi-snapshotter
    - chmod 0755 /csi-snapshotter
  {{- end }}
{{- end }}
